package cn.imu.appdevexperiment2022.two;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import cn.imu.appdevexperiment2022.R;
import cn.imu.appdevexperiment2022.start.BaseActivity;

public class SecondActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        // 获取First传入的数值，从上一个活动得到数据
        Intent intent = getIntent();
        String data = intent.getStringExtra("extra_data");

        Log.d("第二个活动SecondActivity",data+"123");

        // 返回数据给上一个活动
        Button button_second = (Button) findViewById(R.id.button_second);
        button_second.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent();
                intent1.putExtra("data_return","你好 FirstActivit");
                setResult(RESULT_OK,intent1);
                finish();
            }
        });
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("data_return","你好 FirstActivity");
        setResult(RESULT_OK, intent);
        finish();
    }
}